﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace ZhouYu.NewWorld.Web.Attributes
{
    public class ExceptionAttribute:HandleErrorAttribute  //异常过滤器
    {
        /// <summary>
        /// 系统发生异常的操作
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnException(ExceptionContext filterContext)
        {
            //Exception exception = filterContext.Exception;
            //string msg = exception.Message;

            //获取系统的日志
            string exception = filterContext.Exception.ToString();
            string msg = $"时间:{DateTime.Now},系统出错:{exception}";
            //获取文件路径
            string path = "D:\\Exception.txt";
            //如果文件不存在则创建
            /*if (!File.Exists(path))
            {
                File.Create(path);
            }*/
            File.AppendAllText(path, msg);
        }
    }
}